﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SyncStream.Core.Storage
{
    public interface IStorageProvider
    {
        /// <summary>
        /// Creates a store item object based on the unique group id (for simple case the user id),
        /// item id. 
        /// </summary>
        /// <param name="uniqueGroupID">An id to group by the store items if needed</param>
        /// <param name="itemID">An id if the item</param>
        /// <returns>Returns an unique id to track the store item with</returns>
        IStorageItem CreateStorageItem(int uniqueGroupID, int itemID);
        
        /// <summary>
        /// Returns true if a store item entry is already in the store
        /// </summary>
        /// <param name="uniqueGroupID"></param>
        /// <param name="itemID"></param>
        /// <param name="searchOnlyAlive">Searches only the items that are not deleted</param>
        /// <returns></returns>
        bool HasStorageItem (int uniqueGroupID, int itemID, bool searchOnlyAlive);

        /// <summary>
        /// Returns a the store item of the current revision
        /// </summary>
        /// <param name="uniqueGroupID"></param>
        /// <param name="itemID"></param>
        /// <returns></returns>
        IStorageItem GetStorageItem ( int uniqueGroupID, int itemID );

        /// <summary>
        /// Returns a the store item of a specific revision
        /// </summary>
        /// <param name="uniqueGroupID"></param>
        /// <param name="itemID"></param>
        /// <returns></returns>
        IStorageItem GetStorageItemRevision(int uniqueGroupID, int itemID, int revisionID);

        /// Returns a the store item of a specific revision
        /// </summary>
        /// <param name="uniqueGroupID"></param>
        /// <param name="itemID"></param>
        /// <returns></returns>
        IStorageItem GetRevision(IStorageItem item, int revisionID);


        /// <summary>
        /// Deletes a store item. Permanently deletes if specified
        /// </summary>
        /// <param name="uniqueGroupID"></param>
        /// <param name="itemID"></param>
        /// <param name="isPermanentDelete"></param>
        /// <returns></returns>
        int DeleteStorageItem(IStorageItem item, bool isPermanentDelete);


        /// <summary>
        /// Writes data into the store item 
        /// </summary>
        /// <param name="storeItemID"></param>
        /// <param name="startPosition"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        bool WriteStorageItemBlob(IStorageItem item, int startPosition, byte[] data);


        /// <summary>
        /// Increments the store item revision by one. All further writes will be done to the 
        /// new revision 
        /// </summary>
        /// <param name="storeItemID"></param>
        /// <returns></returns>
        IStorageItem IncrementStoreItemRevision(IStorageItem item);

        /// <summary>
        /// Reads bytes from the current rervision store item 
        /// </summary>
        /// <param name="storeItemID"></param>
        /// <param name="startPosition"></param>
        /// <param name="buffer"></param>
        /// <returns></returns>
        bool ReadStoreItemBlob(IStorageItem item, int startPosition, byte[] buffer);

        /// <summary>
        /// Returns the maximum size supported by the blob used for reading and writing
        /// </summary>
        /// <returns></returns>
        int GetMaxBlobSize();
    }
}

